package com.classroompie.classroompieserver.controller;

import com.classroompie.classroompiecommon.result.Result;
import com.classroompie.classroompiepojo.entity.CourseModel;
import com.classroompie.classroompiepojo.request.AddClassInput;
import com.classroompie.classroompiepojo.response.CourseDetailVO;
import com.classroompie.classroompieserver.service.CourseService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiahao
 * @since 2024/6/20 周四
 */
@RestController
@RequestMapping("/course")
@CrossOrigin("*")
public class CourseController {
    private final CourseService courseService;

    public CourseController(CourseService courseService) {
        this.courseService = courseService;
    }

    @PostMapping()
    public void addCourse(@RequestBody @Valid AddClassInput addClassInput) {
        courseService.addCourse(addClassInput);
    }

    @GetMapping("/{id}")
    public Result<CourseDetailVO> getCourse(@PathVariable String id) {
        return Result.success(courseService.getCourse(id));
    }

    @PostMapping("/top/{courseId}")
    public Result<Object> topCourse(@PathVariable String courseId) {
        courseService.topCourse(courseId);
        return Result.success();
    }

    @PostMapping("/archive/{courseId}")
    public Result<Object> archiveCourse(@PathVariable String courseId) {
        courseService.archiveCourse(courseId);
        return Result.success();
    }


}
